package com.cras.webcam.http.servlet;

import com.cras.webcam.http.HttpRequest;
import com.cras.webcam.http.HttpResponse;
import com.cras.webcam.http.Servlet;
import com.cras.webcam.http.exception.HttpRequestExcecption;


public class ServletDispacther {
	public static void dispacth(HttpRequest req, HttpResponse resp) throws HttpRequestExcecption {
		Servlet controller = decideController(req);
		if(null == controller){
			//404 response code
			throw new HttpRequestExcecption("[404]");
		}
		controller.handle(req, resp);
	}
	
	private static Servlet decideController(HttpRequest req){
		String url = req.getUri();
		if(url.contains(".jpg")
				|| url.contains(".png")
				|| url.contains(".js")
				|| url.contains(".css")
				|| url.contains(".html")
				|| url.contains(".text")
				){
			return StaticFileServlet.getInstance();
		}
		/**
		Map<String, String> paramMap = req.getParamters();
		if(null != paramMap && paramMap.isEmpty()){
			return DynamicController.getInstance();
		}**/
		return null;
	}
}
